/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proiect.fis.UI;

import java.util.LinkedList;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import proiect.fis.UI.comboBoxModel.OrasModel;
import proiect.fis.commons.beans.*;

/**
 *
 *
 * @author Boogie-Laptop
 */
public class PackageView extends javax.swing.JPanel {

    private Pachet p;
    private boolean valid = false;

    /**
     * Creates new form PackageView
     */
    public PackageView() {
        initComponents();
        comboBoxDestiantie.setModel(OrasModel.createModel());
        comboBoxSursa.setModel(OrasModel.createModel());
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel4 = new javax.swing.JPanel();
        javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel4 = new javax.swing.JLabel();
        textFieldNumeExpeditor1 = new javax.swing.JTextField();
        javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
        textFieldAdresaExpeditor = new javax.swing.JTextField();
        javax.swing.JLabel jLabel7 = new javax.swing.JLabel();
        textFieldTelefonExpeditor = new javax.swing.JTextField();
        textFieldPrenumeExpeditor = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel9 = new javax.swing.JLabel();
        textFieldNumeDestinatar = new javax.swing.JTextField();
        javax.swing.JLabel jLabel10 = new javax.swing.JLabel();
        textFieldPrenumeDestinatar = new javax.swing.JTextField();
        javax.swing.JLabel jLabel19 = new javax.swing.JLabel();
        textFieldAdresaDestinatar = new javax.swing.JTextField();
        javax.swing.JLabel jLabel20 = new javax.swing.JLabel();
        textFieldTelefonDestinatar = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        javax.swing.JLabel jLabel11 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel12 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel13 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel14 = new javax.swing.JLabel();
        comboBoxStatus = new javax.swing.JComboBox();
        comboBoxDestiantie = new javax.swing.JComboBox();
        comboBoxSursa = new javax.swing.JComboBox();
        buttonValidareRuta = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        javax.swing.JLabel jLabel17 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel18 = new javax.swing.JLabel();
        checkBoxNormal = new javax.swing.JCheckBox();
        checkBoxFragil = new javax.swing.JCheckBox();
        checkBoxPretios = new javax.swing.JCheckBox();
        textFieldGreutate = new javax.swing.JTextField();
        checkBoxPericulos = new javax.swing.JCheckBox();

        setLayout(new java.awt.GridLayout(2, 2));

        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel4.setMinimumSize(new java.awt.Dimension(200, 200));

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Expeditor");

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel4.setText("Nume");

        textFieldNumeExpeditor1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldNumeExpeditor1ActionPerformed(evt);
            }
        });

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel5.setText("Prenume");

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel6.setText("Adresa");

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel7.setText("Telefon");

        textFieldPrenumeExpeditor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldPrenumeExpeditorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textFieldAdresaExpeditor, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textFieldTelefonExpeditor))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(textFieldNumeExpeditor1)
                                    .addComponent(textFieldPrenumeExpeditor, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))))
                        .addContainerGap())))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(textFieldNumeExpeditor1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(textFieldPrenumeExpeditor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(textFieldAdresaExpeditor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(textFieldTelefonExpeditor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(142, Short.MAX_VALUE))
        );

        add(jPanel4);

        jPanel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel8.setText("Destinatar");

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel9.setText("Nume");

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel10.setText("Prenume");

        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel19.setText("Adresa");

        jLabel20.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel20.setText("Telefon");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textFieldAdresaDestinatar, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textFieldTelefonDestinatar))
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
                                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(textFieldNumeDestinatar)
                                    .addComponent(textFieldPrenumeDestinatar))))
                        .addContainerGap())))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(textFieldNumeDestinatar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(textFieldPrenumeDestinatar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(textFieldAdresaDestinatar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(textFieldTelefonDestinatar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(142, Short.MAX_VALUE))
        );

        add(jPanel5);

        jPanel6.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel11.setText("Ruta");

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel12.setText("Destinatie");

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel13.setText("Sursa");

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel14.setText("Status");

        comboBoxStatus.setModel(new DefaultComboBoxModel<String>(StatusPachet.model()));

        buttonValidareRuta.setText("Validare Ruta");
        buttonValidareRuta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonValidareRutaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(comboBoxStatus, 0, 500, Short.MAX_VALUE)
                                    .addComponent(comboBoxDestiantie, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(comboBoxSursa, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(buttonValidareRuta)))
                        .addContainerGap())))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(comboBoxDestiantie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(comboBoxSursa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonValidareRuta)
                .addGap(26, 26, 26)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addContainerGap(119, Short.MAX_VALUE))
        );

        add(jPanel6);

        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel17.setText("Other");

        jLabel18.setText("Greutate");

        buttonGroup1.add(checkBoxNormal);
        checkBoxNormal.setText("Normal");

        buttonGroup1.add(checkBoxFragil);
        checkBoxFragil.setText("Fragil");

        buttonGroup1.add(checkBoxPretios);
        checkBoxPretios.setText("Pretios");

        textFieldGreutate.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        textFieldGreutate.setText("0");

        buttonGroup1.add(checkBoxPericulos);
        checkBoxPericulos.setText("Periculos");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textFieldGreutate, javax.swing.GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(checkBoxPericulos)
                            .addComponent(checkBoxPretios)
                            .addComponent(checkBoxFragil)
                            .addComponent(checkBoxNormal))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(textFieldGreutate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(checkBoxNormal)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkBoxFragil)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkBoxPretios)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkBoxPericulos)
                .addContainerGap(110, Short.MAX_VALUE))
        );

        add(jPanel3);
    }// </editor-fold>//GEN-END:initComponents

    private void textFieldNumeExpeditor1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldNumeExpeditor1ActionPerformed
    }//GEN-LAST:event_textFieldNumeExpeditor1ActionPerformed

    private void textFieldPrenumeExpeditorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldPrenumeExpeditorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textFieldPrenumeExpeditorActionPerformed

    private void buttonValidareRutaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonValidareRutaActionPerformed
        Pachet p1= new Pachet();
        
        Oras s=null;
        Oras d=null;

        if (isValidInput()) {
            p1 = this.getPachet();
            
            s = (Oras) comboBoxSursa.getModel().getSelectedItem();
            d = (Oras) comboBoxDestiantie.getModel().getSelectedItem();
        }else{
            return ;
        }
        if (p1!=null&&p1.createRute(s, d)) {
            JOptionPane.showMessageDialog(this, "Ruta selectata a fost gasita cu succes!","Succes!", JOptionPane.PLAIN_MESSAGE);
            valid = true;
        } else {
            JOptionPane.showMessageDialog(this, "Ruta selectata NU corespunde cerintelor!","Eroare!", JOptionPane.ERROR_MESSAGE);
            valid = false;
        }
        p1 = null;


    }//GEN-LAST:event_buttonValidareRutaActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton buttonValidareRuta;
    private javax.swing.JCheckBox checkBoxFragil;
    private javax.swing.JCheckBox checkBoxNormal;
    private javax.swing.JCheckBox checkBoxPericulos;
    private javax.swing.JCheckBox checkBoxPretios;
    private javax.swing.JComboBox comboBoxDestiantie;
    private javax.swing.JComboBox comboBoxStatus;
    private javax.swing.JComboBox comboBoxSursa;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JTextField textFieldAdresaDestinatar;
    private javax.swing.JTextField textFieldAdresaExpeditor;
    private javax.swing.JTextField textFieldGreutate;
    private javax.swing.JTextField textFieldNumeDestinatar;
    private javax.swing.JTextField textFieldNumeExpeditor1;
    private javax.swing.JTextField textFieldPrenumeDestinatar;
    private javax.swing.JTextField textFieldPrenumeExpeditor;
    private javax.swing.JTextField textFieldTelefonDestinatar;
    private javax.swing.JTextField textFieldTelefonExpeditor;
    // End of variables declaration//GEN-END:variables

    public void setPachet(Pachet p) {
        if (p != null) {
            this.p = p;
            this.textFieldNumeDestinatar.setText(p.getDestinatar().getNume());
            this.textFieldPrenumeDestinatar.setText(p.getDestinatar().getPrenume());
            this.textFieldAdresaDestinatar.setText(p.getDestinatar().getAdresa());
            this.textFieldTelefonDestinatar.setText(p.getDestinatar().getNrTelefon());
            this.textFieldNumeExpeditor1.setText(p.getExpeditor().getNume());
            this.textFieldPrenumeExpeditor.setText(p.getExpeditor().getPrenume());
            this.textFieldAdresaExpeditor.setText(p.getExpeditor().getAdresa());
            this.textFieldTelefonExpeditor.setText(p.getExpeditor().getNrTelefon());

            this.comboBoxSursa.getModel().setSelectedItem(p.getRuta().get(0));
            this.comboBoxDestiantie.getModel().setSelectedItem(p.getRuta().get(p.getRuta().size() - 1));
            this.comboBoxStatus.setSelectedItem(p.getStatus().name());

            this.textFieldGreutate.setText(p.getGretutate() + "");

            switch (p.getTip()) {
                case NORMAL:
                    this.checkBoxNormal.setSelected(true);
                    break;
                case FRAGIL:
                    this.checkBoxFragil.setSelected(true);
                    break;
                case PRETIOS:
                    this.checkBoxPretios.setSelected(true);
                    break;
                case PERICULOS:
                    this.checkBoxPericulos.setSelected(true);
                    break;
            }
        }
    }

    public boolean isValidInput() {
        if (textFieldAdresaDestinatar.getText().contentEquals("")
                || textFieldAdresaExpeditor.getText().contentEquals("")
                || textFieldGreutate.getText().contentEquals("")
                || textFieldNumeDestinatar.getText().contentEquals("")
                || textFieldPrenumeDestinatar.getText().contentEquals("")
                || textFieldNumeExpeditor1.getText().contentEquals("")
                || textFieldPrenumeExpeditor.getText().contentEquals("")
                || textFieldTelefonDestinatar.getText().contentEquals("")
                || textFieldTelefonExpeditor.getText().contentEquals("")) {

            return false;
        }
        try {
            Double.parseDouble(textFieldGreutate.getText());
        } catch (NumberFormatException e) {
            return false;
        }


        return true;
    }

    public Pachet getPachet() {

        Persoana destinatar;
        Persoana expeditor;
        Oras destinatie;
        Oras sursa;
        if (p == null) {
            p = new Pachet();
            destinatar = new Persoana();
            expeditor = new Persoana();
        } else {
            destinatar = p.getDestinatar();
            expeditor = p.getExpeditor();
        }

        destinatar.setAdresa(this.textFieldAdresaDestinatar.getText());
        destinatar.setNrTelefon(this.textFieldTelefonDestinatar.getText());
        destinatar.setNume(this.textFieldNumeDestinatar.getText());
        destinatar.setPrenume(this.textFieldPrenumeDestinatar.getText());
        p.setDestinatar(destinatar);



        expeditor.setAdresa(this.textFieldAdresaExpeditor.getText());
        expeditor.setNrTelefon(this.textFieldTelefonExpeditor.getText());
        expeditor.setNume(this.textFieldNumeExpeditor1.getText());
        expeditor.setPrenume(this.textFieldPrenumeExpeditor.getText());
        p.setExpeditor(expeditor);

        p.setGretutate(Double.parseDouble(textFieldGreutate.getText()));

        p.setStatus(StatusPachet.valueOf(this.comboBoxStatus.getSelectedItem().toString()));

        if (this.checkBoxFragil.isSelected()) {
            p.setTip(TipPachet.FRAGIL);
        } else if (this.checkBoxNormal.isSelected()) {
            p.setTip(TipPachet.NORMAL);
        } else if (this.checkBoxPretios.isSelected()) {
            p.setTip(TipPachet.PRETIOS);
        }else{
            p.setTip(TipPachet.PERICULOS);
        }


        sursa = (Oras) comboBoxSursa.getModel().getSelectedItem();
        destinatie = (Oras) comboBoxDestiantie.getModel().getSelectedItem();

        p.createRute(sursa, destinatie);


        return p;
    }
}
